//
//  main.m
//  nonameTest
//
//  Created by dllo on 16/5/14.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import <Foundation/Foundation.h>
void change (float *a ,float *b);
void changeInt (int *a ,int *b);
void changeChar (char *a ,char *b);
int strlenS (char *p);
void strcpyS (char *p, char *q);
void seven(double *a, double *b, double *c);

int main(int argc, const char * argv[]) {
    
#if 0
    int number = 88;
    int number2 = 77;
    
    int *x = &number;
    int *y = &number2;
    
    printf("%d\n", *x);
    printf("%d\n", *y);
    
#endif
    
#if 0
    int array[10] = {0,2};
    int *p = array;
    
    printf("*p  = %d\n", *p);
    printf("*(p + 1) = %d\n", *(p + 1));
    printf("*p + 1 = %d\n", *p + 1);
    
    
    
    
    
#endif
    
    
#if 0
    float a = 5.4;
    float b = 7.8;
    
    change(&a, &b);
    
    printf("%f\n", a);
    
    
    
#endif
    
    
#if 0
    int a = 5;
    int b = 9;
    
    changeInt(&a, &b);
    
    printf("%d\n", a);
    
    
#endif
    
    
#if 0
    char a = 'l';
    char b = 'f';
    
    changeChar(&a, &b);
    
    printf("%c\n", a);
    printf("%c\n", b);
    
    
    
    
#endif
    
    
#if 0
    int a[5];
   // int *p = 0;
    int max = 0;
    for (int i = 0; i < 5; i++) {
        a[i] = arc4random() % 100 + 1;
    }
    int *aAdd[5];
    for (int i = 0; i < 5; i++) {
        aAdd[i] = &a[i];
        max = max > *aAdd[i] ? max : *aAdd[i];
    }
    int k = 0;
    for (int i = 0; i < 5; i++) {
        if (*aAdd[i] == max) {
            k = i;
        }
    }
    
    for (int i = 0; i < 5; i++) {
        printf("%d,", a[i]);
    }
    
    //k即为最大值的地址,交换k与初始值地址
    int temp;
    temp = *aAdd[k];
    *aAdd[k] = *aAdd[0];
    *aAdd[0] = temp;
    
    
    
    printf("第一位为:%d\n", a[0]);
    for (int i = 0; i < 5;i++) {
        printf("%d,",a[i]);
    }
    
    
//    int *aAddress = &a[0];
//    int *maxAddress = &max;
//    
//    int temp;
//    temp = *aAddress;
//    *aAddress = *maxAddress;
//    *maxAddress = temp;
    
    
    
    
    
    
    
    
#endif
    
    
#if 0
    int a[5];
    // int *p = 0;
    int min = 100;
    for (int i = 0; i < 5; i++) {
        a[i] = arc4random() % 100 + 1;
    }
    int *aAdd[5];
    for (int i = 0; i < 5; i++) {
        aAdd[i] = &a[i];
        min = min < *aAdd[i] ? min : *aAdd[i];
    }
    int k = 0;
    for (int i = 0; i < 5; i++) {
        if (*aAdd[i] == min) {
            k = i;
        }
    }
    
    for (int i = 0; i < 5; i++) {
        printf("%d,", a[i]);
    }
    printf("\n");
    
    //k即为最小值的地址,交换k与初始值地址
    int temp;
    temp = *aAdd[k];
    *aAdd[k] = *aAdd[0];
    *aAdd[0] = temp;
    
    
    for (int i = 0; i < 5;i++) {
        printf("%d,",a[i]);
    }
    
    
#endif
    
    
#if 0
    int a[10];
    int *p = a;
    int max = 0;
    int min = 100;
    for(int i = 0;i < 10; i++) {
        p[i] = arc4random() % 100 + 1;
        max = max > p[i] ? max : p[i];
        min = min < p[i] ? min : p[i];
    }
    for (int i = 0; i < 10; i++) {
        if (max == p[i]) {
            int temp = p[i];
            p[i] = p[9];
            p[9] = temp;
        }
        if (min == p[i]) {
            int temp = p[i];
            p[i] = p[0];
            p[0] = temp;
        }
    }
    
    for (int i = 0; i < 10; i++) {
        printf("%d,",p[i]);
    }
    
    
    
    
    
    
#endif
    
    
#if 1
    double a = 5.5;
    double b = 4.4;
    double c = 6.6;
    seven(&a, &b, &c);
    printf("%lf,%lf,%lf", a, b, c);
    
#endif
    
    
#if 0
    char a[] = "aoshufeidan";
    
    int x = strlenS(a);
    printf("字符串长度为:%d\n",x);
    
    
    
    
#endif
    
#if 0
    char a[] = "arthur";
    char b[10] = {'0'};
    
    strcpyS(b, a);
    printf("%s\n",b);
    
#endif
    
    
#if 0
    char a[] = "A00r25484t4545h545u7158r11154";
    char *p = a;
    for (int i = 0;1 > 0; i++) {
        if(p[i] >= 'a' && p[i] <= 'z') {
            *p = p[i];
            p++;
        } else if (p[i] >= 'A' && p[i] <= 'Z') {
            *p = p[i];
            p++;
        } else if (p[i] == '\0'){
            *p = p[i];
            break;
        }
    }
    
    printf("%s\n",a);
    
    
    
#endif
    
    
    
    
    return 0;
}

void change (float *a ,float *b) {
    int temp  = 0.0;
    temp = *a;
    *a = *b;
    *b = temp;
    
//    printf("%f\n", *a);
}


void changeInt (int *a ,int *b) {
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

void changeChar (char *a ,char *b) {
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

void seven(double *a, double *b, double *c) {
    double max = *a > *b ? *a : *b;
    max = max > *c ? max : *c;
    double min = *a < *b ? *a : *b;
    min = min < *c ? min : *c;
    double mid = *a + *b + *c - max - min;
    
    
    if (mid == *a) {
        double temp = *b;
        *b = *c;
        *c = temp;
    } else if (mid == *b) {
        double temp = *a;
        *a = *c;
        *c = temp;
    } else if (mid == *c){
        double temp = *a;
        *a = *b;
        *b = temp;
    }
    printf("%.2lf\n",mid);
    
    printf("a = %.2lf ,b = %.2lf, c = %.2lf\n", *a, *b, *c);
}

int strlenS (char *p){
    for(int i = 0; 1 > 0;i++){
        if(p[i] == '\0') {
            return i;
        }
    }
}

void strcpyS (char *p, char *q) {
    for (int i = 0; 1 > 0; i++) {
        p[i] = q[i];
        if (q[i] == '\0') {
            break;
        }
    }
}

